package oop.java0322;



public class Mall {
    String mallName;
    String address;
    Card[] card;
    int count;


    //构造方法
    public Mall() {
        card = new Card[5];
    }

    public Mall(String mallName, String address) {
        //this();
        card = new Card[5];
        this.mallName = mallName;
        this.address = address;
    }

    //添加新会员开卡的方法
    public boolean add(Card c) {
        if (count >= card.length) {
            return false;
        }
//        for (int i = 0; i < count; i++) {
//            if (card[i].cardNo.equals(c.cardNo)) {
//                System.out.println("卡号以存在，添加失败!");
//                return false;
//            }
//        }
        if (checkNo(c.getCardNo())) {
            System.out.println("卡号以存在，添加失败!");
            return false;
        }
        card[count++] = c;
        System.out.println("添加成功！");
        return true;

    }

    //查看指定会员号在不在数组中
    public boolean checkNo(String cardNo) {
        for (int i = 0; i < count; i++) {
            if (card[i].getCardNo().equals(cardNo)) {
                //已经存在
                return true;
            }
        }
        //新的会员号，可以去添加
        return false;
    }

    //兑换奖品
    public boolean exchange(String cardNo, int no) {
        for (int i = 0; i < count; i++) {
            if (card[i].getCardNo().equals(cardNo)) {
                switch (no) {
                    case 1: {
                        if (card[i].getScore() >= 100) {
                            card[i].decreaseScore(no);
                            System.out.println("成功兑换餐巾纸一包");
                            return true;
                        }
                        System.out.println("积分不足！");
                        return false;
                    }
                    case 2: {
                        if (card[i].getScore() >= 400) {
                            card[i].decreaseScore(no);
                            card[i].setScore(card[i].getScore());
                            System.out.println("成功兑换剃须刀一把");
                            return true;
                        }
                        System.out.println("积分不足！");
                        return false;
                    }
                    case 3: {
                        if (card[i].getScore() >= 1000) {
                            card[i].decreaseScore(no);
                            System.out.println("成功兑换炒锅一个");
                            return true;
                        }
                        System.out.println("积分不足！");
                        return false;
                    }
                    default: {
                        break;
                    }
                }
            }
        }
        System.out.println("账号不存在！");
        return false;
    }

    //增加积分
    public boolean increaseScore(String cardNo, int score) {
        for (int i = 0; i < count; i++) {
            if (card[i].getCardNo().equals(cardNo)) {
                card[i].increaseScore(score);
                System.out.println("操作成功！");
                return true;
            }
        }
        System.out.println("会员号不存在！");
        return false;
    }

    //查看会员信息
    public boolean showInfo() {
        for (int i = 0; i < count; i++) {
            card[i].showInfo();
//                System.out.println("卡号：" + card[i].cardNo);
//                System.out.println("持卡人姓名：" + card[i].name);
//                System.out.println("联系方式：" + card[i].telePhone);
//                System.out.println("积分：" + card[i].score + "分");

        }
        return true;
    }


    //展示商城信息
    public void showMall() {
        System.out.println("name:" + mallName);
        System.out.println("address:" + address);
        System.out.println("会员数量:" + count);
    }
}
